home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / REVJUL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-07  |  931 b   |  42 lines

  1. #include <mem.h>
  2. #include <stdio.h>
  3.  
  4. char *RevJul( int jul )
  5. {
  6.     static int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
  7.     static char date[11];
  8.     int days_year;
  9.     int n = 1;
  10.     int year;
  11.  
  12.     year = 80;
  13.     memset(date, 0, sizeof(date));
  14.     days[2] = 28;
  15.     do {
  16.         if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
  17.             days_year = 366;
  18.         else
  19.             days_year = 365;
  20.         year++, jul -= days_year;
  21.     } while (jul > 0);
  22.     year--, jul += days_year;
  23.     if (days_year == 366)
  24.         days[2] = 29;
  25.     do
  26.         jul -= days[n++];
  27.     while (jul > 0);
  28.     --n, jul += days[n];
  29.  
  30.     if ( n < 0 || n > 12 )
  31.         return( "00-00-00" );
  32.  
  33.     if ( jul < 0 || jul > 31 )
  34.         return( "00-00-00" );
  35.  
  36.     if ( year < 0 || year > 99 )
  37.         return( "00-00-00" );
  38.  
  39.     sprintf(date, "%02d-%02d-%02d", n, jul, year);
  40.     return (date);
  41. }
  42.